package com.sdy.kzyy.web.task;

import com.sdy.kzyy.biz.service.StoreInventoryService;
import com.sdy.kzyy.biz.service.StoreService;
import com.sdy.kzyy.biz.service.impl.UserServiceImpl;
import com.sdy.mvc.annotation.TaskSync;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * <p>
 * 重置记录各个药店每天的订单数的map
 * </p>
 *
 * @author fb
 * @since 2020/3/12
 */
@Slf4j
@Component
public class ResetStoreMapTask {

    @Autowired
    private StoreInventoryService storeInventoryService;
    @Autowired
    private StoreService storeService;

    @Scheduled(cron="0 03 0 * * ?")
    @TaskSync
    public void clearMapKey() {
        for(Iterator<Map.Entry<String, AtomicInteger>> it = UserServiceImpl.restMap.entrySet().iterator(); it.hasNext(); ) {
            // 此句不能少，否则，删除当前节点，指针无法找到下一节点
            Map.Entry<String, AtomicInteger> item = it.next();
            it.remove();
        }
        log.info("已经执行完成!");
    }

/*    @Scheduled(cron="0 05 0 * * ?")
    @TaskSync
    public void refreshLimiationCount() {
        if(storeInventoryService.updateStoreOnceCount()) {
            log.info("可预约口罩数修改成功!");
        }else {
            log.info("可预约口罩数修改失败!");
        }
    }*/

/*    @Scheduled(cron="0 07 0 * * ?")
    @TaskSync
    public void refreshExtractTime() {
        if(storeService.updateExtractTime()) {
            log.info("药店能领取口罩时间修改成功!");
        }else {
            log.info("药店能领取口罩时间修改失败!");
        }
    }*/

}
